﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using CreditAgricole.Framework;

namespace CreditAgricole.PageCodeBehind
{
    public partial class ElementMenu : UserControl
    {

        #region Properties

        /// <summary>
        /// lnkElement control.
        /// </summary>
        protected HyperLink lnkElement;

        /// <summary>
        /// lblElementMenu control.
        /// </summary>
        protected Label lblElementMenu;

        /// <summary>
        /// Label property
        /// </summary>
        /// 
        public string LblElement
        {
            get { return lblElementMenu.Text; }
            set { lblElementMenu.Text = value; }
        }

        /// <summary>
        /// IsSiteMenu private access
        /// </summary>
        private bool isSiteMenu = false;

        /// <summary>
        /// IsSiteMenu public access. 
        /// </summary>
        public bool SiteMenu
        {
            get { return isSiteMenu; }
            set { isSiteMenu = value; }
        }

        /// <summary>
        /// LinkElement public access
        /// </summary>
        public string LinkElement
        {
            get
            {
                if (SiteMenu)
                {
                    return string.Format("{0}/{1}", SPContext.Current.RootFolderUrl, lnkElement.NavigateUrl);
                }
                else
                {
                    return string.Format("{0}/{1}?selected={2}", SPContext.Current.RootFolderUrl, Constants.ActivitiesPageName, lnkElement.NavigateUrl);
                }
            }
            set
            {
                if (SiteMenu)
                {
                    lnkElement.NavigateUrl = string.Format("{0}/{1}", SPContext.Current.RootFolderUrl, value);
                }
                else
                {
                    lnkElement.NavigateUrl = string.Format("{0}/{1}?selected={2}", SPContext.Current.RootFolderUrl, Constants.ActivitiesPageName, value);
                }
            }
        }

        #endregion

        /// <summary>
        /// Select Menu item by applying proper style
        /// </summary>
        public void Selected()
        {
            if (SiteMenu == false)
            {
                if (!lblElementMenu.CssClass.Contains("SelectedElementMenu"))
                {
                    lblElementMenu.CssClass += "SelectedElementMenu";
                }
            }
            else
            {
                if (!lblElementMenu.CssClass.Contains("SiteSelectedElementMenu"))
                {
                    lblElementMenu.CssClass += "SiteSelectedElementMenu";
                }
            }
        }
    }
}
